<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Input Output Template</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
MathJax = {
	tex: {
		inlineMath: '$', '$'], ['\\(', '\\)'
	},
	svg: {
		fontCache: 'global'
	}
};
</script>
<script type="text/javascript" id="MathJax-script" async
	src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>

<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html">
<img src="../docs-assets/Inform.png" height=72">
</a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../indocn.html">indoc</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=18> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="../../../inweb/index.html">inweb</a></li>
<li><a href="../../../intest/index.html">intest</a></li>

</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Input Output Template' generated by Inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../extensions.html">Kits</a></li><li><a href="index.html">Architecture32Kit</a></li><li><b>Input Output Template</b></li></ul></div>
<p class="purpose">Access to the keyboard and to textual windows.</p>

<ul class="toc"><li><a href="S-io.html#SP1">&#167;1. Rocks</a></li><li><a href="S-io.html#SP2">&#167;2. Transcript support</a></li><li><a href="S-io.html#SP3">&#167;3. Dictionary Parameters</a></li><li><a href="S-io.html#SP4">&#167;4. Extracting Verb Numbers</a></li><li><a href="S-io.html#SP5">&#167;5. Variables and Arrays</a></li><li><a href="S-io.html#SP6">&#167;6. Dictionary words</a></li><li><a href="S-io.html#SP7">&#167;7. Keyboard Input</a></li><li><a href="S-io.html#SP8">&#167;8. Buffer Functions</a></li><li><a href="S-io.html#SP9">&#167;9. Dictionary Functions</a></li><li><a href="S-io.html#SP10">&#167;10. Command Tables</a></li><li><a href="S-io.html#SP11">&#167;11. Action functions</a></li><li><a href="S-io.html#SP12">&#167;12. Glulx-Only Printing Routines</a></li><li><a href="S-io.html#SP13">&#167;13. The Screen</a></li><li><a href="S-io.html#SP14">&#167;14. Window Colours</a></li><li><a href="S-io.html#SP15">&#167;15. Main Window</a></li><li><a href="S-io.html#SP16">&#167;16. Status Line</a></li><li><a href="S-io.html#SP17">&#167;17. Quotation Boxes</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Rocks. </b>These are unique ID codes used to mark resources; think of them as inedible
cookies.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GG_MAINWIN_ROCK</span><span class="plain-syntax">        </span><span class="constant-syntax">201</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GG_STATUSWIN_ROCK</span><span class="plain-syntax">      </span><span class="constant-syntax">202</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GG_QUOTEWIN_ROCK</span><span class="plain-syntax">       </span><span class="constant-syntax">203</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GG_SAVESTR_ROCK</span><span class="plain-syntax">        </span><span class="constant-syntax">301</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GG_SCRIPTSTR_ROCK</span><span class="plain-syntax">      </span><span class="constant-syntax">302</span><span class="plain-syntax">;</span>
<span class="plain-syntax">#</span><span class="identifier-syntax">Ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">COMMAND_STREAM</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GG_COMMANDWSTR_ROCK</span><span class="plain-syntax">    </span><span class="constant-syntax">303</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GG_COMMANDRSTR_ROCK</span><span class="plain-syntax">    </span><span class="constant-syntax">304</span><span class="plain-syntax">;</span>
<span class="plain-syntax">#</span><span class="identifier-syntax">Endif</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GG_SCRIPTFREF_ROCK</span><span class="plain-syntax">     </span><span class="constant-syntax">401</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GG_FOREGROUNDCHAN_ROCK</span><span class="plain-syntax"> </span><span class="constant-syntax">410</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GG_BACKGROUNDCHAN_ROCK</span><span class="plain-syntax"> </span><span class="constant-syntax">411</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. Transcript support. </b>This is a mode in which the transcript of text in the main window is being
written out to an external file.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_TranscriptIsOn</span></span> tests whether this mode is on. <span class="extract"><span class="extract-syntax">VM_TranscriptOn</span></span> should
be called only if it is off, and tries to turn it on, returning <span class="extract"><span class="extract-syntax">true</span></span> or <span class="extract"><span class="extract-syntax">false</span></span>
according to whether or not it succeeds. <span class="extract"><span class="extract-syntax">VM_TranscriptOff</span></span> should be called
only if scripting is on: this always succeeds.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_scriptfref</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_scriptstr</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_TranscriptIsOn</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_scriptstr</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_TranscriptOn</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="reserved-syntax">true</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_scriptfref</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_scriptfref</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_fileref_create_by_prompt</span><span class="plain-syntax">(</span><span class="constant-syntax">$102</span><span class="plain-syntax">, </span><span class="constant-syntax">$05</span><span class="plain-syntax">, </span><span class="identifier-syntax">GG_SCRIPTFREF_ROCK</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_scriptfref</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="comment-syntax">stream_open_file</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">gg_scriptstr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_stream_open_file_uni</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_scriptfref</span><span class="plain-syntax">, </span><span class="constant-syntax">$05</span><span class="plain-syntax">, </span><span class="identifier-syntax">GG_SCRIPTSTR_ROCK</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_scriptstr</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="comment-syntax">Could not open selected file; select again</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">glk_fileref_destroy</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_scriptfref</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_scriptfref</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">glk_window_set_echo_stream</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_mainwin</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_scriptstr</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_TranscriptOff</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">glk_stream_close</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_scriptstr</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">); </span><span class="comment-syntax">stream_close</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gg_scriptstr</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. Dictionary Parameters. </b>Each word in the dictionary data structure has two metadata fields, known
for traditional Inform 6 reasons as "dictionary parameters 1 and 2". Number 1
is a bitmap: some of the higher bits are written by the I6 compiler only when
certain compile options are set, but they will be for the code which I7
generates. Bit 6 is currently never written by I6; bit 5, marking singular
nouns, is never used by this parser.
</p>

<p class="commentary">(For speed reasons, reading of <span class="extract"><span class="extract-syntax">DICTPAR1_NOUN</span></span> and <span class="extract"><span class="extract-syntax">DICTPAR1_PREP</span></span> is done
directly by <span class="extract"><span class="extract-syntax">ParserKit</span></span> rather than by calling functions here.)
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICT_ENTRY_BYTES</span><span class="plain-syntax"> = </span><span class="constant-syntax">12</span><span class="plain-syntax">+</span><span class="identifier-syntax">DICT_WORD_SIZE</span><span class="plain-syntax">*</span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> #</span><span class="identifier-syntax">dict_par1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">DICT_WORD_SIZE</span><span class="plain-syntax">*</span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">+4+1;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> #</span><span class="identifier-syntax">dict_par2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">DICT_WORD_SIZE</span><span class="plain-syntax">*</span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">+4+3;</span>

<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_VERB</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_META</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_PLURAL</span><span class="plain-syntax"> = </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_PREP</span><span class="plain-syntax"> = </span><span class="constant-syntax">8</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_SING</span><span class="plain-syntax"> = </span><span class="constant-syntax">16</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_BIT6</span><span class="plain-syntax"> = </span><span class="constant-syntax">32</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_TRUNC</span><span class="plain-syntax"> = </span><span class="constant-syntax">64</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICTPAR1_NOUN</span><span class="plain-syntax"> = </span><span class="constant-syntax">128</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">WordMarkedAsVerb</span><span class="plain-syntax"> </span><span class="identifier-syntax">w</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">w</span><span class="plain-syntax">) &amp;&amp; ((</span><span class="identifier-syntax">w</span><span class="plain-syntax">-&gt;#</span><span class="identifier-syntax">dict_par1</span><span class="plain-syntax">) &amp; </span><span class="identifier-syntax">DICTPAR1_VERB</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">WordMarkedAsMeta</span><span class="plain-syntax"> </span><span class="identifier-syntax">w</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">w</span><span class="plain-syntax">) &amp;&amp; ((</span><span class="identifier-syntax">w</span><span class="plain-syntax">-&gt;#</span><span class="identifier-syntax">dict_par1</span><span class="plain-syntax">) &amp; </span><span class="identifier-syntax">DICTPAR1_META</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">WorkMarkedAsUntruncatedPlural</span><span class="plain-syntax"> </span><span class="identifier-syntax">w</span><span class="plain-syntax"> </span><span class="identifier-syntax">b</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">w</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">b</span><span class="plain-syntax"> = </span><span class="identifier-syntax">w</span><span class="plain-syntax">-&gt;#</span><span class="identifier-syntax">dict_par1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">b</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">DICTPAR1_TRUNC</span><span class="plain-syntax">) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">b</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">DICTPAR1_PLURAL</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. Extracting Verb Numbers. </b>A long tale of woe lies behind the following. Infocom games stored verb numbers
in a single byte in dictionary entries, but they did so counting downwards, so
that verb number 0 was stored as 255, 1 as 254, and so on. Inform followed
suit so that debugging of Inform 1 could be aided by using the then-available
tools for dumping dictionaries from Infocom story files; by using the Infocom
format for dictionary tables, Inform's life was easier.
</p>

<p class="commentary">But there was an implicit restriction there of 255 distinct verbs (not 256
since not all words were verbs). When Glulx raised almost all of the Z-machine
limits, it made space for 65535 verbs instead of 255, but it appears that
nobody remembered to implement this in I6-for-Glulx and the Glulx form of
the I6 library. This was only put right in March 2009, and the following
routine was added to concentrate lookups of this field in one place.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">DictionaryWordToVerbNum</span><span class="plain-syntax"> </span><span class="identifier-syntax">w</span><span class="plain-syntax"> </span><span class="identifier-syntax">verbnum</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">w</span><span class="plain-syntax"> = </span><span class="identifier-syntax">w</span><span class="plain-syntax"> + #</span><span class="identifier-syntax">dict_par2</span><span class="plain-syntax"> - </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">aloads</span><span class="plain-syntax"> </span><span class="identifier-syntax">w</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax"> </span><span class="identifier-syntax">verbnum</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">verbnum</span><span class="plain-syntax"> = </span><span class="constant-syntax">$ffff</span><span class="plain-syntax">-</span><span class="identifier-syntax">verbnum</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">verbnum</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. Variables and Arrays. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_event</span><span class="plain-syntax"> --&gt; </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax"> </span><span class="identifier-syntax">buffer</span><span class="plain-syntax"> </span><span class="constant-syntax">28</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_mainwin</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_savestr</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">#</span><span class="identifier-syntax">Ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">COMMAND_STREAM</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_commandstr</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_command_reading</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;      </span><span class="comment-syntax">true if gg_commandstr is being replayed</span>
<span class="plain-syntax">#</span><span class="identifier-syntax">Endif</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_foregroundchan</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_backgroundchan</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">INPUT_BUFFER_LEN</span><span class="plain-syntax"> = </span><span class="constant-syntax">260</span><span class="plain-syntax">;    </span><span class="comment-syntax">No extra byte necessary</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">MAX_BUFFER_WORDS</span><span class="plain-syntax"> = </span><span class="constant-syntax">20</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">PARSE_BUFFER_LEN</span><span class="plain-syntax"> = </span><span class="constant-syntax">61</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">Array</span><span class="plain-syntax">  </span><span class="identifier-syntax">buffer</span><span class="plain-syntax">   --&gt; </span><span class="identifier-syntax">INPUT_BUFFER_LEN</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax">  </span><span class="identifier-syntax">buffer2</span><span class="plain-syntax">  --&gt; </span><span class="identifier-syntax">INPUT_BUFFER_LEN</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax">  </span><span class="identifier-syntax">buffer3</span><span class="plain-syntax">  --&gt; </span><span class="identifier-syntax">INPUT_BUFFER_LEN</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax">  </span><span class="identifier-syntax">parse</span><span class="plain-syntax">     --&gt; </span><span class="identifier-syntax">PARSE_BUFFER_LEN</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax">  </span><span class="identifier-syntax">parse2</span><span class="plain-syntax">    --&gt; </span><span class="identifier-syntax">PARSE_BUFFER_LEN</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. Dictionary words. </b>This tests whether an address is probably that of a dictionary word. It's used
only for debugging output, so the false positives here really do not matter.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_ProbablyDictionaryAddress</span><span class="plain-syntax"> </span><span class="identifier-syntax">addr</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">addr</span><span class="plain-syntax">-&gt;0 == </span><span class="constant-syntax">$60</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. Keyboard Input. </b>The VM must provide three routines for keyboard input:
</p>

<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">VM_KeyChar()</span></span> waits for a key to be pressed and then returns the
character chosen as a unicode character. Function keys are mapped to unicode
characters so that Z-Machine and Glulxe key input can be handled the same.
</li><li>(b) <span class="extract"><span class="extract-syntax">VM_KeyDelay(N)</span></span> waits up to \(N/10\) seconds for a key to be pressed,
returning the unicode character if so, or 0 if not.
</li><li>(c) <span class="extract"><span class="extract-syntax">VM_ReadKeyboard(b, t)</span></span> reads a whole newline-terminated command
into the buffer <span class="extract"><span class="extract-syntax">b</span></span>. If the <span class="extract"><span class="extract-syntax">t</span></span> parser table is specified then it also parses it.
</li></ul>
<p class="commentary">There are elaborations to do with mouse clicks, but this isn't the place
to document all of that.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_KeyChar</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">done</span><span class="plain-syntax"> </span><span class="identifier-syntax">res</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="identifier-syntax">jx</span><span class="plain-syntax"> </span><span class="identifier-syntax">ch</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">jx</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ch</span><span class="plain-syntax">; </span><span class="comment-syntax">squash compiler warnings</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">win</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_mainwin</span><span class="plain-syntax">;</span>
<span class="plain-syntax">#</span><span class="identifier-syntax">Ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">COMMAND_STREAM</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_commandstr</span><span class="plain-syntax"> ~= </span><span class="constant-syntax">0</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">gg_command_reading</span><span class="plain-syntax"> ~= </span><span class="reserved-syntax">false</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">done</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_get_line_stream</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_commandstr</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">, </span><span class="constant-syntax">31</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">done</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">glk_stream_close</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_commandstr</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_commandstr</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_command_reading</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="comment-syntax">fall through to normal user input.</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="comment-syntax">Trim the trailing newline</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">done</span><span class="plain-syntax">-1) == </span><span class="constant-syntax">10</span><span class="plain-syntax">) </span><span class="identifier-syntax">done</span><span class="plain-syntax"> = </span><span class="identifier-syntax">done</span><span class="plain-syntax">-1;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">res</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">-&gt;0;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">res</span><span class="plain-syntax"> == </span><span class="character-syntax">'\') {</span>
<span class="character-syntax">                res = 0;</span>
<span class="character-syntax">                for (ix=1 : ix&lt;done : ix++) {</span>
<span class="character-syntax">                    ch = gg_arguments-&gt;ix;</span>
<span class="character-syntax">                    if (ch &gt;= '</span><span class="constant-syntax">0</span><span class="character-syntax">' &amp;&amp; ch &lt;= '</span><span class="constant-syntax">9</span><span class="character-syntax">') {</span>
<span class="character-syntax">                        @shiftl res 4 res;</span>
<span class="character-syntax">                        res = res + (ch-'</span><span class="constant-syntax">0</span><span class="character-syntax">');</span>
<span class="character-syntax">                    } else if (ch &gt;= '</span><span class="identifier-syntax">a</span><span class="character-syntax">' &amp;&amp; ch &lt;= '</span><span class="identifier-syntax">f</span><span class="character-syntax">') {</span>
<span class="character-syntax">                        @shiftl res 4 res;</span>
<span class="character-syntax">                        res = res + (ch+10-'</span><span class="identifier-syntax">a</span><span class="character-syntax">');</span>
<span class="character-syntax">                    } else if (ch &gt;= '</span><span class="identifier-syntax">A</span><span class="character-syntax">' &amp;&amp; ch &lt;= '</span><span class="identifier-syntax">F</span><span class="character-syntax">') {</span>
<span class="character-syntax">                        @shiftl res 4 res;</span>
<span class="character-syntax">                        res = res + (ch+10-'</span><span class="identifier-syntax">A</span><span class="character-syntax">');</span>
<span class="character-syntax">                    }</span>
<span class="character-syntax">                }</span>
<span class="character-syntax">            }</span>
<span class="character-syntax">            jump KCPContinue;</span>
<span class="character-syntax">        }</span>
<span class="character-syntax">    }</span>
<span class="character-syntax">#Endif;</span>
<span class="character-syntax">    done = false;</span>
<span class="character-syntax">    glk_request_char_event(win);</span>
<span class="character-syntax">    while (~~done) {</span>
<span class="character-syntax">        glk_select(gg_event);</span>
<span class="character-syntax">        switch (gg_event--&gt;0) {</span>
<span class="character-syntax">          evtype_CharInput:</span>
<span class="character-syntax">            if (gg_event--&gt;1 == win) {</span>
<span class="character-syntax">                res = gg_event--&gt;2;</span>
<span class="character-syntax">                done = true;</span>
<span class="character-syntax">            }</span>
<span class="character-syntax">        }</span>
<span class="character-syntax">    }</span>
<span class="character-syntax">#Ifdef COMMAND_STREAM;</span>
<span class="character-syntax">    if (gg_commandstr ~= 0 &amp;&amp; gg_command_reading == false) {</span>
<span class="character-syntax">        if (res &lt; 32 || res &gt;= 256 || (res == '</span><span class="plain-syntax">\</span><span class="character-syntax">' or '</span><span class="plain-syntax"> </span><span class="character-syntax">')) {</span>
<span class="character-syntax">            glk_put_char_stream(gg_commandstr, '</span><span class="plain-syntax">\</span><span class="character-syntax">');</span>
<span class="character-syntax">            done = 0;</span>
<span class="character-syntax">            jx = res;</span>
<span class="character-syntax">            for (ix=0 : ix&lt;8 : ix++) {</span>
<span class="character-syntax">                @ushiftr jx 28 ch;</span>
<span class="character-syntax">                @shiftl jx 4 jx;</span>
<span class="character-syntax">                ch = ch &amp; $0F;</span>
<span class="character-syntax">                if (ch ~= 0 || ix == 7) done = 1;</span>
<span class="character-syntax">                if (done) {</span>
<span class="character-syntax">                    if (ch &gt;= 0 &amp;&amp; ch &lt;= 9) ch = ch + '</span><span class="constant-syntax">0</span><span class="character-syntax">';</span>
<span class="character-syntax">                    else                    ch = (ch - 10) + '</span><span class="identifier-syntax">A</span><span class="character-syntax">';</span>
<span class="character-syntax">                    glk_put_char_stream(gg_commandstr, ch);</span>
<span class="character-syntax">                }</span>
<span class="character-syntax">            }</span>
<span class="character-syntax">        } else {</span>
<span class="character-syntax">            glk_put_char_stream(gg_commandstr, res);</span>
<span class="character-syntax">        }</span>
<span class="character-syntax">        glk_put_char_stream(gg_commandstr, 10); </span><span class="comment-syntax">newline</span>
<span class="character-syntax">    }</span>
<span class="character-syntax">  .KCPContinue;</span>
<span class="character-syntax">#Endif;</span>
<span class="character-syntax">    return MapGlkKeyCodeToUnicode(res);</span>
<span class="character-syntax">];</span>

<span class="character-syntax">[ VM_KeyDelay tenths  key done;</span>
<span class="character-syntax">    glk_request_char_event(gg_mainwin);</span>
<span class="character-syntax">    glk_request_timer_events(tenths*100);</span>
<span class="character-syntax">    while (~~done) {</span>
<span class="character-syntax">        glk_select(gg_event);</span>
<span class="character-syntax">        if (gg_event--&gt;0 == evtype_Timer or evtype_CharInput) {</span>
<span class="character-syntax">            key = gg_event--&gt;2;</span>
<span class="character-syntax">            done = true;</span>
<span class="character-syntax">        }</span>
<span class="character-syntax">    }</span>
<span class="character-syntax">    glk_cancel_char_event(gg_mainwin);</span>
<span class="character-syntax">    glk_request_timer_events(0);</span>
<span class="character-syntax">    return key;</span>
<span class="character-syntax">];</span>

<span class="character-syntax">Array UnicodeWhitespace --&gt; 133 160 5760 8232 8233 8239 8287 12288;</span>
<span class="character-syntax">Constant UnicodeWhitespaceLen = 8;</span>

<span class="character-syntax">[ VM_ReadKeyboard  a_buffer a_table done ix chr;</span>
<span class="character-syntax">#Ifdef COMMAND_STREAM;</span>
<span class="character-syntax">    if (gg_commandstr ~= 0 &amp;&amp; gg_command_reading ~= false) {</span>
<span class="character-syntax">        done = glk_get_line_stream_uni(gg_commandstr, a_buffer+WORDSIZE,</span>
<span class="character-syntax">            (INPUT_BUFFER_LEN-1)-1);</span>
<span class="character-syntax">        if (done == 0) {</span>
<span class="character-syntax">            glk_stream_close(gg_commandstr, 0);</span>
<span class="character-syntax">            gg_commandstr = 0;</span>
<span class="character-syntax">            gg_command_reading = false;</span>
<span class="character-syntax">        } else {</span>
<span class="character-syntax">            </span><span class="comment-syntax">Trim the trailing newline</span>
<span class="character-syntax">            if ((a_buffer+WORDSIZE)--&gt;(done-1) == 10) done = done-1;</span>
<span class="character-syntax">            a_buffer--&gt;0 = done;</span>
<span class="character-syntax">            VM_Style(INPUT_VMSTY);</span>
<span class="character-syntax">            glk_put_buffer_uni(a_buffer+WORDSIZE, done);</span>
<span class="character-syntax">            VM_Style(NORMAL_VMSTY);</span>
<span class="character-syntax">            print "^";</span>
<span class="character-syntax">            jump KPContinue;</span>
<span class="character-syntax">        }</span>
<span class="character-syntax">    }</span>
<span class="character-syntax">#Endif;</span>
<span class="character-syntax">    done = false;</span>
<span class="character-syntax">    glk_request_line_event_uni(gg_mainwin, a_buffer+WORDSIZE, INPUT_BUFFER_LEN-1, 0);</span>
<span class="character-syntax">    while (~~done) {</span>
<span class="character-syntax">        glk_select(gg_event);</span>
<span class="character-syntax">        switch (gg_event--&gt;0) {</span>
<span class="character-syntax">          evtype_LineInput:</span>
<span class="character-syntax">            if (gg_event--&gt;1 == gg_mainwin) {</span>
<span class="character-syntax">                a_buffer--&gt;0 = gg_event--&gt;2;</span>
<span class="character-syntax">                done = true;</span>
<span class="character-syntax">            }</span>
<span class="character-syntax">        }</span>
<span class="character-syntax">    }</span>
<span class="character-syntax">    </span><span class="comment-syntax">Manually echo the command if required</span>
<span class="character-syntax">    if (BasicInformKit`MANUAL_INPUT_ECHOING_CFGF &amp;&amp; Cached_Glk_Gestalts--&gt;gestalt_LineInputEcho) {</span>
<span class="character-syntax">        glk_set_style(style_Input);</span>
<span class="character-syntax">        glk_put_buffer_uni(a_buffer + WORDSIZE, a_buffer--&gt;0);</span>
<span class="character-syntax">        glk_set_style(style_Normal);</span>
<span class="character-syntax">        glk_put_char(10); </span><span class="comment-syntax">newline</span>
<span class="character-syntax">    }</span>
<span class="character-syntax">#Ifdef COMMAND_STREAM;</span>
<span class="character-syntax">    if (gg_commandstr ~= 0 &amp;&amp; gg_command_reading == false) {</span>
<span class="character-syntax">        glk_put_buffer_stream(gg_commandstr, a_buffer+WORDSIZE, a_buffer--&gt;0);</span>
<span class="character-syntax">        glk_put_char_stream(gg_commandstr, 10); </span><span class="comment-syntax">newline</span>
<span class="character-syntax">    }</span>
<span class="character-syntax">  .KPContinue;</span>
<span class="character-syntax">#Endif;</span>

<span class="character-syntax">    for ( ix = 1 : ix &lt;= (a_buffer--&gt;0) : ix++ ) {</span>
<span class="character-syntax">      chr = a_buffer--&gt;ix;</span>
<span class="character-syntax">      if ((chr &lt;= 32) || (((chr &gt;= 8192) &amp;&amp; (chr &lt;= 8202))))</span>
<span class="character-syntax">        a_buffer--&gt;ix = 32;</span>
<span class="character-syntax">      else {</span>
<span class="character-syntax">        @binarysearch chr WORDSIZE UnicodeWhitespace WORDSIZE UnicodeWhitespaceLen 0 0 chr;</span>
<span class="character-syntax">    if (chr) a_buffer--&gt;ix = 32;</span>
<span class="character-syntax">      }</span>
<span class="character-syntax">    }</span>
<span class="character-syntax">    if (a_table) {</span>
<span class="character-syntax">        VM_Tokenise(a_buffer, a_table);</span>
<span class="character-syntax">    }</span>
<span class="character-syntax">    </span><span class="comment-syntax">It's time to close any quote window we've got going.</span>
<span class="character-syntax">    if (gg_quotewin) {</span>
<span class="character-syntax">        glk_window_close(gg_quotewin, 0);</span>
<span class="character-syntax">        gg_quotewin = 0;</span>
<span class="character-syntax">        Quote_Window.glk_ref = 0;</span>
<span class="character-syntax">    }</span>
<span class="character-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. Buffer Functions. </b>A "buffer", in this sense, is an array containing a stream of characters
typed from the keyboard; a "parse buffer" is an array which resolves this
into individual words, pointing to the relevant entries in the dictionary
structure. Because each VM has its own format for each of these arrays (not
to mention the dictionary), we have to provide some standard operations
needed by the rest of the template as routines for each VM.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_CopyBuffer(to, from)</span></span> copies one buffer into another.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_PrintBuffer(buf)</span></span> prints a buffer.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_PrintToBuffer(buf, len, a, b, c)</span></span> prints something into a buffer.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_Tokenise(buff, parse_buff)</span></span> takes the text in the buffer <span class="extract"><span class="extract-syntax">buff</span></span> and
produces the corresponding data in the parse buffer <span class="extract"><span class="extract-syntax">parse_buff</span></span> &mdash; this is
called tokenisation since the characters are divided into words: in traditional
computing jargon, such clumps of characters treated syntactically as units
are called tokens.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">LTI_Insert</span></span> is documented in the DM4 and the <span class="extract"><span class="extract-syntax">LTI</span></span> prefix stands for
"Language To Informese": it's used only by translations into non-English
languages of play, and is not called in the template.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_CopyBuffer</span><span class="plain-syntax"> </span><span class="identifier-syntax">bto</span><span class="plain-syntax"> </span><span class="identifier-syntax">bfrom</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0: </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">INPUT_BUFFER_LEN</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">bto</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">bfrom</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_PrintBuffer</span><span class="plain-syntax"> </span><span class="identifier-syntax">buf</span><span class="plain-syntax">  </span><span class="identifier-syntax">buf_inner</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">len</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;0) + </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">len</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="identifier-syntax">char</span><span class="plain-syntax">) </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_PrintToBuffer</span><span class="plain-syntax"> </span><span class="identifier-syntax">buf</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax"> </span><span class="identifier-syntax">b</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">b</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="reserved-syntax">metaclass</span><span class="plain-syntax">(</span><span class="identifier-syntax">a</span><span class="plain-syntax">) == </span><span class="identifier-syntax">Object</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">a</span><span class="plain-syntax">.#</span><span class="identifier-syntax">b</span><span class="plain-syntax"> == </span><span class="identifier-syntax">WORDSIZE</span>
<span class="plain-syntax">            &amp;&amp; </span><span class="reserved-syntax">metaclass</span><span class="plain-syntax">(</span><span class="identifier-syntax">a</span><span class="plain-syntax">.</span><span class="identifier-syntax">b</span><span class="plain-syntax">) == </span><span class="identifier-syntax">String</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;0 = </span><span class="identifier-syntax">Glulx_PrintAnyToArrayUni</span><span class="plain-syntax">(</span><span class="identifier-syntax">buf</span><span class="plain-syntax">+</span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">, </span><span class="identifier-syntax">len</span><span class="plain-syntax">, </span><span class="identifier-syntax">a</span><span class="plain-syntax">.</span><span class="identifier-syntax">b</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="reserved-syntax">metaclass</span><span class="plain-syntax">(</span><span class="identifier-syntax">a</span><span class="plain-syntax">) == </span><span class="identifier-syntax">Routine</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;0 = </span><span class="identifier-syntax">Glulx_PrintAnyToArrayUni</span><span class="plain-syntax">(</span><span class="identifier-syntax">buf</span><span class="plain-syntax">+</span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">, </span><span class="identifier-syntax">len</span><span class="plain-syntax">, </span><span class="identifier-syntax">a</span><span class="plain-syntax">, </span><span class="identifier-syntax">b</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;0 = </span><span class="identifier-syntax">Glulx_PrintAnyToArrayUni</span><span class="plain-syntax">(</span><span class="identifier-syntax">buf</span><span class="plain-syntax">+</span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">, </span><span class="identifier-syntax">len</span><span class="plain-syntax">, </span><span class="identifier-syntax">a</span><span class="plain-syntax">, </span><span class="identifier-syntax">b</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="reserved-syntax">metaclass</span><span class="plain-syntax">(</span><span class="identifier-syntax">a</span><span class="plain-syntax">) == </span><span class="identifier-syntax">Routine</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;0 = </span><span class="identifier-syntax">Glulx_PrintAnyToArrayUni</span><span class="plain-syntax">(</span><span class="identifier-syntax">buf</span><span class="plain-syntax">+</span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">, </span><span class="identifier-syntax">len</span><span class="plain-syntax">, </span><span class="identifier-syntax">a</span><span class="plain-syntax">, </span><span class="identifier-syntax">b</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;0 = </span><span class="identifier-syntax">Glulx_PrintAnyToArrayUni</span><span class="plain-syntax">(</span><span class="identifier-syntax">buf</span><span class="plain-syntax">+</span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">, </span><span class="identifier-syntax">len</span><span class="plain-syntax">, </span><span class="identifier-syntax">a</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;0 &gt; </span><span class="identifier-syntax">len</span><span class="plain-syntax">) </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;0 = </span><span class="identifier-syntax">len</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">];</span>

<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOWERCASE_BUF_SIZE</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">*</span><span class="identifier-syntax">DICT_WORD_SIZE</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_lowercasebuf</span><span class="plain-syntax"> --&gt; </span><span class="identifier-syntax">LOWERCASE_BUF_SIZE</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_Tokenise</span><span class="plain-syntax"> </span><span class="identifier-syntax">buf</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">cx</span><span class="plain-syntax"> </span><span class="identifier-syntax">numwords</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax"> </span><span class="identifier-syntax">bx</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="identifier-syntax">wx</span><span class="plain-syntax"> </span><span class="identifier-syntax">wpos</span><span class="plain-syntax"> </span><span class="identifier-syntax">wlen</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> </span><span class="identifier-syntax">res</span><span class="plain-syntax"> </span><span class="identifier-syntax">dictlen</span><span class="plain-syntax"> </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> </span><span class="identifier-syntax">bytesperword</span><span class="plain-syntax"> </span><span class="identifier-syntax">uninormavail</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">len</span><span class="plain-syntax"> = </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">buf</span><span class="plain-syntax"> = </span><span class="identifier-syntax">buf</span><span class="plain-syntax">+</span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">First, split the buffer up into words. We use the standard Infocom</span>
<span class="plain-syntax">    </span><span class="comment-syntax">list of word separators (comma, period, double-quote).</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">cx</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">numwords</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">cx</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">len</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">cx</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">len</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">cx</span><span class="plain-syntax"> == </span><span class="character-syntax">' '</span><span class="plain-syntax">) </span><span class="identifier-syntax">cx</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">cx</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">len</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">bx</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cx</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">cx</span><span class="plain-syntax"> == </span><span class="character-syntax">'.'</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="character-syntax">','</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="character-syntax">'"'</span><span class="plain-syntax">) </span><span class="identifier-syntax">cx</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">cx</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">len</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">cx</span><span class="plain-syntax"> ~= </span><span class="character-syntax">' '</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="character-syntax">'.'</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="character-syntax">','</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="character-syntax">'"'</span><span class="plain-syntax">) </span><span class="identifier-syntax">cx</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">numwords</span><span class="plain-syntax">*3+2) = (</span><span class="identifier-syntax">cx</span><span class="plain-syntax">-</span><span class="identifier-syntax">bx</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">numwords</span><span class="plain-syntax">*3+3) = </span><span class="constant-syntax">1</span><span class="plain-syntax">+</span><span class="identifier-syntax">bx</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">numwords</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">numwords</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">MAX_BUFFER_WORDS</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;0 = </span><span class="identifier-syntax">numwords</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Now we look each word up in the dictionary.</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">dictlen</span><span class="plain-syntax"> = #</span><span class="identifier-syntax">dictionary_table</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">bytesperword</span><span class="plain-syntax"> = </span><span class="identifier-syntax">DICT_WORD_SIZE</span><span class="plain-syntax"> * </span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">uninormavail</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">gestalt_UnicodeNorm</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">wx</span><span class="plain-syntax">=0 : </span><span class="identifier-syntax">wx</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">numwords</span><span class="plain-syntax"> : </span><span class="identifier-syntax">wx</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">wlen</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">wx</span><span class="plain-syntax">*3+2);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">wpos</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">wx</span><span class="plain-syntax">*3+3);</span>

<span class="plain-syntax">        </span><span class="comment-syntax">Copy the word into the gg_tokenbuf array, clipping to DICT_WORD_SIZE</span>
<span class="plain-syntax">        </span><span class="comment-syntax">characters and lower case. We'll do this in two steps, because</span>
<span class="plain-syntax">        </span><span class="comment-syntax">lowercasing might (theoretically) condense characters and allow more</span>
<span class="plain-syntax">        </span><span class="comment-syntax">to fit into gg_tokenbuf.</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">wlen</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">LOWERCASE_BUF_SIZE</span><span class="plain-syntax">) </span><span class="identifier-syntax">wlen</span><span class="plain-syntax"> = </span><span class="identifier-syntax">LOWERCASE_BUF_SIZE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">cx</span><span class="plain-syntax"> = </span><span class="identifier-syntax">wpos</span><span class="plain-syntax"> - </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ix</span><span class="plain-syntax">=0 : </span><span class="identifier-syntax">ix</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">wlen</span><span class="plain-syntax"> : </span><span class="identifier-syntax">ix</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">cx</span><span class="plain-syntax">+</span><span class="identifier-syntax">ix</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_lowercasebuf</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ch</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">wlen</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_buffer_to_lower_case_uni</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_lowercasebuf</span><span class="plain-syntax">, </span><span class="identifier-syntax">LOWERCASE_BUF_SIZE</span><span class="plain-syntax">, </span><span class="identifier-syntax">wlen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">uninormavail</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="comment-syntax">Also normalize the Unicode &mdash; combine accent marks with letters</span>
<span class="plain-syntax">            </span><span class="comment-syntax">where possible.</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">wlen</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_buffer_canon_normalize_uni</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_lowercasebuf</span><span class="plain-syntax">, </span><span class="identifier-syntax">LOWERCASE_BUF_SIZE</span><span class="plain-syntax">, </span><span class="identifier-syntax">wlen</span><span class="plain-syntax">); </span><span class="comment-syntax">buffer_canon_normalize_uni</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">wlen</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">DICT_WORD_SIZE</span><span class="plain-syntax">) </span><span class="identifier-syntax">wlen</span><span class="plain-syntax"> = </span><span class="identifier-syntax">DICT_WORD_SIZE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ix</span><span class="plain-syntax">=0: </span><span class="identifier-syntax">ix</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">wlen</span><span class="plain-syntax"> : </span><span class="identifier-syntax">ix</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_tokenbuf</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_lowercasebuf</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">ix</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (: </span><span class="identifier-syntax">ix</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">DICT_WORD_SIZE</span><span class="plain-syntax"> : </span><span class="identifier-syntax">ix</span><span class="plain-syntax">++) </span><span class="identifier-syntax">gg_tokenbuf</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">        </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = #</span><span class="identifier-syntax">dictionary_table</span><span class="plain-syntax"> + </span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        @</span><span class="identifier-syntax">binarysearch</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_tokenbuf</span><span class="plain-syntax"> </span><span class="identifier-syntax">bytesperword</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> </span><span class="identifier-syntax">DICT_ENTRY_BYTES</span><span class="plain-syntax"> </span><span class="identifier-syntax">dictlen</span><span class="plain-syntax"> </span><span class="constant-syntax">4</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax"> </span><span class="identifier-syntax">res</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">wx</span><span class="plain-syntax">*3+1) = </span><span class="identifier-syntax">res</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">LTI_Insert</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">ch</span><span class="plain-syntax">  </span><span class="identifier-syntax">b</span><span class="plain-syntax"> </span><span class="identifier-syntax">y</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Protect us from strict mode, as this isn't an array in quite the</span>
<span class="plain-syntax">    </span><span class="comment-syntax">sense it expects</span>
<span class="plain-syntax">    </span><span class="comment-syntax">(This is not an issue now that buffer is a word array, but I'm</span>
<span class="plain-syntax">    </span><span class="comment-syntax">keeping the alias.)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">b</span><span class="plain-syntax"> = </span><span class="identifier-syntax">buffer</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Insert character ch into buffer at point i.</span>
<span class="plain-syntax">    </span><span class="comment-syntax">Being careful not to let the buffer possibly overflow:</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">b</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">y</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">INPUT_BUFFER_LEN</span><span class="plain-syntax">) </span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">INPUT_BUFFER_LEN</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Move the subsequent text along one character:</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">y</span><span class="plain-syntax">=</span><span class="identifier-syntax">y</span><span class="plain-syntax">+1 : </span><span class="identifier-syntax">y</span><span class="plain-syntax">&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> : </span><span class="identifier-syntax">y</span><span class="plain-syntax">--) </span><span class="identifier-syntax">b</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">b</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">y</span><span class="plain-syntax">-1);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">b</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ch</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">And the text is now one character longer:</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">b</span><span class="plain-syntax">--&gt;0 &lt; </span><span class="identifier-syntax">INPUT_BUFFER_LEN</span><span class="plain-syntax">) (</span><span class="identifier-syntax">b</span><span class="plain-syntax">--&gt;0)++;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. Dictionary Functions. </b>Again, the dictionary structure is differently arranged on the different VMs.
This is a data structure containing, in compressed form, the text of all the
words to be recognised by tokenisation (above). In I6 for Glulx, a dictionary
word is represented at run-time by its record's address in the dictionary.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_InvalidDictionaryAddress(A)</span></span> tests whether <span class="extract"><span class="extract-syntax">A</span></span> is a valid record address
in the dictionary data structure. In Glulx, dictionary records might in
theory be anywhere in the 2 GB or so of possible memory, but we can rule
out negative addresses. (This allows \(-1\), say, to be used as a value meaning
"not a valid dictionary word".)
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_DictionaryAddressToNumber(A)</span></span> and <span class="extract"><span class="extract-syntax">VM_NumberToDictionaryAddress(N)</span></span>
convert between word addresses and their run-time representations:
since, on Glulx, they are the same, these are each the identity function.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_InvalidDictionaryAddress</span><span class="plain-syntax"> </span><span class="identifier-syntax">addr</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">addr</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_DictionaryAddressToNumber</span><span class="plain-syntax"> </span><span class="identifier-syntax">w</span><span class="plain-syntax">; </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">w</span><span class="plain-syntax">; ];</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_NumberToDictionaryAddress</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">; </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">; ];</span>

<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_tokenbuf</span><span class="plain-syntax"> --&gt; </span><span class="identifier-syntax">DICT_WORD_SIZE</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GGWordCompare</span><span class="plain-syntax"> </span><span class="identifier-syntax">str1</span><span class="plain-syntax"> </span><span class="identifier-syntax">str2</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="identifier-syntax">jx</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ix</span><span class="plain-syntax">=0 : </span><span class="identifier-syntax">ix</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">DICT_WORD_SIZE</span><span class="plain-syntax"> : </span><span class="identifier-syntax">ix</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">jx</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">str1</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">ix</span><span class="plain-syntax">) - (</span><span class="identifier-syntax">str2</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">ix</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">jx</span><span class="plain-syntax"> ~= </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">jx</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. Command Tables. </b>The VM is also generated containing a data structure for the grammar
produced by I6's <span class="extract"><span class="extract-syntax">Verb</span></span> and <span class="extract"><span class="extract-syntax">Extend</span></span> directives: this is essentially a
list of command verbs such as DROP or PUSH, together with a list of
synonyms, and then the grammar for the subsequent commands to be
recognised by the parser.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_CommandTableAddress</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (#</span><span class="identifier-syntax">grammar_table</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">i</span><span class="plain-syntax">+1);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_PrintCommandWords</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">wd</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax"> </span><span class="identifier-syntax">dictlen</span><span class="plain-syntax"> </span><span class="identifier-syntax">entrylen</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">dictlen</span><span class="plain-syntax"> = #</span><span class="identifier-syntax">dictionary_table</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">entrylen</span><span class="plain-syntax"> = </span><span class="identifier-syntax">DICT_WORD_SIZE</span><span class="plain-syntax"> + </span><span class="constant-syntax">7</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">=0 : </span><span class="identifier-syntax">j</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">dictlen</span><span class="plain-syntax"> : </span><span class="identifier-syntax">j</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">wd</span><span class="plain-syntax"> = #</span><span class="identifier-syntax">dictionary_table</span><span class="plain-syntax"> + </span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax"> + </span><span class="identifier-syntax">entrylen</span><span class="plain-syntax">*</span><span class="identifier-syntax">j</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">DictionaryWordToVerbNum</span><span class="plain-syntax">(</span><span class="identifier-syntax">wd</span><span class="plain-syntax">) == </span><span class="identifier-syntax">i</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"'"</span><span class="plain-syntax">, (</span><span class="identifier-syntax">address</span><span class="plain-syntax">) </span><span class="identifier-syntax">wd</span><span class="plain-syntax">, </span><span class="string-syntax">"' "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. Action functions. </b>This looks up the address of a function like <span class="extract"><span class="extract-syntax">TakeSub</span></span> from the table of
"action subroutines".
</p>

<p class="commentary">Strangely, Glulx's action routines table is numbered in an off-by-one way
compared to the Z-machine's: hence the <span class="extract"><span class="extract-syntax">+1</span></span> here.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_ActionFunction</span><span class="plain-syntax"> </span><span class="identifier-syntax">act</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> #</span><span class="identifier-syntax">actions_table</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">act</span><span class="plain-syntax">+1);</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. Glulx-Only Printing Routines. </b>Partly because of the smallness of the range of representable values in
the Z-machine, there is little run-time type-checking that can be done:
for instance a dictionary address cannot be distinguished from a function
address because they are encoded differently, so that a function address
(which is packed) could well coincide with that of a dictionary word (which
is not). On Glulx these restrictions are somewhat lifted, so that it's
possible to write a routine which can look at a value, work out what it
must mean, and print it suitably. This is only possible up to a point &mdash;
for instance, it can't distinguish an integer from a function address &mdash;
and in I7 the use of this sort of trick is much less important because
type-checking in the Inform compiler handles the problem much better. Still,
we retain some Glulx-only features because they are convenient for writing
external files to disc, for instance, something which the Z-machine can't
do in any case.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">Glulx_PrintAnything</span></span> handles strings, functions (with optional arguments),
objects, object properties (with optional arguments), and dictionary words.
(Object property printing has been somewhat simplified from the ideal version
of this function in order to avoid calling the CA__Pr veneer function.)
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">Glulx_PrintAnyToArray</span></span> does the same, but the output is sent to a byte
array in memory. The first two arguments must be the array address and
length; subsequent arguments are as for <span class="extract"><span class="extract-syntax">Glulx_PrintAnything</span></span>. The return
value is the number of characters output. If the output is longer than the
array length given, the extra characters are discarded, so the array does
not overflow. (However, the return value is the total length of the output,
including discarded characters.) The character set stored here is ZSCII,
not Unicode.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">Glulx_PrintAnyToArrayUni</span></span> does the same again, but the output is sent to a
word array in memory. The stored characters are Unicode code points.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">Glulx_ChangeAnyToCString</span></span> calls <span class="extract"><span class="extract-syntax">Glulx_PrintAnyToArray</span></span> on a particular
array, then amends the result to make it a C-style string &mdash; that is, a
sequence of byte-sized characters which are null terminated. The character
set stored here is once again ZSCII, not Unicode.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="comment-syntax">Glulx_PrintAnything()                    &lt;nothing printed&gt;</span>
<span class="comment-syntax">Glulx_PrintAnything(0)                   &lt;nothing printed&gt;</span>
<span class="comment-syntax">Glulx_PrintAnything("string");           print (string) "string";</span>
<span class="comment-syntax">Glulx_PrintAnything('word')              print (address) 'word';</span>
<span class="comment-syntax">Glulx_PrintAnything(obj)                 print (name) obj;</span>
<span class="comment-syntax">Glulx_PrintAnything(obj, prop)           obj.prop();  NOTE: Using PrintOrRun</span>
<span class="comment-syntax">Glulx_PrintAnything(obj, prop, args...)  obj.prop(args...); NOTE: Unsupported</span>
<span class="comment-syntax">Glulx_PrintAnything(func)                func();</span>
<span class="comment-syntax">Glulx_PrintAnything(func, args...)       func(args...);</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Glulx_PrintAnything</span><span class="plain-syntax"> </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="identifier-syntax">mclass</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj</span><span class="plain-syntax">-&gt;0 == </span><span class="constant-syntax">$60</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="comment-syntax">Dictionary word. Metaclass() can't catch this case, so we do it manually</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="identifier-syntax">address</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">mclass</span><span class="plain-syntax"> = </span><span class="reserved-syntax">metaclass</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">mclass</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">      </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">:</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">      </span><span class="identifier-syntax">String</span><span class="plain-syntax">:</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">      </span><span class="identifier-syntax">Routine</span><span class="plain-syntax">:</span>
<span class="plain-syntax">        </span><span class="comment-syntax">Call the function with all the arguments which are already</span>
<span class="plain-syntax">        </span><span class="comment-syntax">on the stack.</span>
<span class="plain-syntax">        @</span><span class="identifier-syntax">call</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">      </span><span class="identifier-syntax">Object</span><span class="plain-syntax">:</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="identifier-syntax">name</span><span class="plain-syntax">) </span><span class="identifier-syntax">obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="comment-syntax">Push the object back onto the stack, and call the</span>
<span class="plain-syntax">            </span><span class="comment-syntax">veneer routine that handles obj.prop() calls.</span>
<span class="plain-syntax">            @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">            @</span><span class="identifier-syntax">call</span><span class="plain-syntax"> </span><span class="identifier-syntax">PrintOrRun</span><span class="plain-syntax"> </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Glulx_PrintAnyToArray</span><span class="plain-syntax"> </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> </span><span class="identifier-syntax">arr</span><span class="plain-syntax"> </span><span class="identifier-syntax">arrlen</span><span class="plain-syntax"> </span><span class="identifier-syntax">str</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldstr</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax"> </span><span class="identifier-syntax">arr</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax"> </span><span class="identifier-syntax">arrlen</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> = </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> - </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">oldstr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_stream_get_current</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">str</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_stream_open_memory</span><span class="plain-syntax">(</span><span class="identifier-syntax">arr</span><span class="plain-syntax">, </span><span class="identifier-syntax">arrlen</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">str</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">glk_stream_set_current</span><span class="plain-syntax">(</span><span class="identifier-syntax">str</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    @</span><span class="identifier-syntax">call</span><span class="plain-syntax"> </span><span class="identifier-syntax">Glulx_PrintAnything</span><span class="plain-syntax"> </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">glk_stream_set_current</span><span class="plain-syntax">(</span><span class="identifier-syntax">oldstr</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffff</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">str</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">glk</span><span class="plain-syntax"> </span><span class="constant-syntax">$0044</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="comment-syntax">stream_close</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Glulx_PrintAnyToArrayUni</span><span class="plain-syntax"> </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> </span><span class="identifier-syntax">arr</span><span class="plain-syntax"> </span><span class="identifier-syntax">arrlen</span><span class="plain-syntax"> </span><span class="identifier-syntax">str</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldstr</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax"> </span><span class="identifier-syntax">arr</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax"> </span><span class="identifier-syntax">arrlen</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> = </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> - </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">oldstr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_stream_get_current</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">str</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_stream_open_memory_uni</span><span class="plain-syntax">(</span><span class="identifier-syntax">arr</span><span class="plain-syntax">, </span><span class="identifier-syntax">arrlen</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">str</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">glk_stream_set_current</span><span class="plain-syntax">(</span><span class="identifier-syntax">str</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    @</span><span class="identifier-syntax">call</span><span class="plain-syntax"> </span><span class="identifier-syntax">Glulx_PrintAnything</span><span class="plain-syntax"> </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">glk_stream_set_current</span><span class="plain-syntax">(</span><span class="identifier-syntax">oldstr</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffff</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">str</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">glk</span><span class="plain-syntax"> </span><span class="constant-syntax">$0044</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="comment-syntax">stream_close</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GG_ANYTOSTRING_LEN</span><span class="plain-syntax"> </span><span class="constant-syntax">66</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">AnyToStrArr</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">GG_ANYTOSTRING_LEN</span><span class="plain-syntax">+1;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">Glulx_ChangeAnyToCString</span><span class="plain-syntax"> </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GG_ANYTOSTRING_LEN</span><span class="plain-syntax">-2;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> = </span><span class="identifier-syntax">AnyToStrArr</span><span class="plain-syntax">+1;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="identifier-syntax">sp</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> = </span><span class="identifier-syntax">_vararg_count</span><span class="plain-syntax">+2;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">call</span><span class="plain-syntax"> </span><span class="identifier-syntax">Glulx_PrintAnyToArray</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">AnyToStrArr</span><span class="plain-syntax">-&gt;0 = </span><span class="constant-syntax">$E0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">len</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">GG_ANYTOSTRING_LEN</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">len</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GG_ANYTOSTRING_LEN</span><span class="plain-syntax">-1;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">AnyToStrArr</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">len</span><span class="plain-syntax">+1) = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">AnyToStrArr</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. The Screen. </b>Our generic screen model is that the screen is made up of windows: we tend
to refer only to two of these, the main window and the status line, but
others may also exist from time to time. Windows have unique ID numbers:
the special window ID \(-1\) means "all windows" or "the entire screen",
which usually amounts to the same thing.
</p>

<p class="commentary">Screen height and width are measured in characters, with respect to the
fixed-pitch font used for the status line. The main window normally contains
variable-pitch text which may even have been kerned, and character dimensions
make little sense there.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_ClearScreen</span><span class="plain-syntax"> </span><span class="identifier-syntax">window</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">window</span><span class="plain-syntax"> == </span><span class="identifier-syntax">WIN_ALL</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">WIN_MAIN</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">glk_window_clear</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_mainwin</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">glk_window_close</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Quote_Window</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">window</span><span class="plain-syntax"> == </span><span class="identifier-syntax">WIN_ALL</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">WIN_STATUS</span><span class="plain-syntax">) </span><span class="identifier-syntax">glk_window_clear</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_ScreenWidth</span><span class="plain-syntax">  </span><span class="identifier-syntax">id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_mainwin</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_statuswin</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">glk_window_get_size</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_ScreenHeight</span><span class="plain-syntax">  </span><span class="identifier-syntax">height</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">glk_window_get_size</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_mainwin</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">height</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">glk_window_get_size</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">height</span><span class="plain-syntax"> = </span><span class="identifier-syntax">height</span><span class="plain-syntax"> + </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">height</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. Window Colours. </b>We can now change foreground and background colours in both Z-Machine and Glulx
(through a widely implement extension.) Inform does not keep track of which
colours have been set.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_SetWindowColours</span><span class="plain-syntax"> </span><span class="identifier-syntax">fg</span><span class="plain-syntax"> </span><span class="identifier-syntax">bg</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">gestalt_GarglkText_FAKE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">garglk_set_zcolors</span><span class="plain-syntax">(</span><span class="identifier-syntax">fg</span><span class="plain-syntax">, </span><span class="identifier-syntax">bg</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_SetReverseMode</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">gestalt_GarglkText_FAKE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">garglk_set_reversevideo</span><span class="plain-syntax">(</span><span class="identifier-syntax">val</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. Main Window. </b>The part of the screen on which commands and responses are printed, which
ordinarily occupies almost all of the screen area.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_MainWindow()</span></span> switches printing back from another window, usually the
status line, to the main window.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_MainWindow</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">glk_set_window</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_mainwin</span><span class="plain-syntax">); </span><span class="comment-syntax">set_window</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">statuswin_current</span><span class="plain-syntax">=0;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>&#167;16. Status Line. </b>Despite the name, the status line need not be a single line at the top of
the screen: that's only the conventional default arrangement. It can expand
to become the equivalent of an old-fashioned VT220 terminal, with menus
and grids and mazes displayed lovingly in character graphics, or it can
close up to invisibility.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_StatusLineHeight(n)</span></span> sets the status line to have a height of <span class="extract"><span class="extract-syntax">n</span></span> lines
of type. (The width of the status line is always the width of the whole
screen, and the position is always at the top, so the height is the only
controllable aspect.) The \(n=0\) case makes the status line disappear.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">VM_MoveCursorInStatusLine(line, column)</span></span> switches printing to the status line,
positioning the "cursor" &mdash; the position at which printing will begin &mdash;
at the given character grid position \((line, column)\). Line 1 represents the top
line; line 2 is underneath, and so on; columns are similarly numbered from
1 at the left.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_StatusLineHeight</span><span class="plain-syntax"> </span><span class="identifier-syntax">hgt</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">hgt</span><span class="plain-syntax"> == </span><span class="identifier-syntax">statuswin_cursize</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">glk_window_set_arrangement</span><span class="plain-syntax">(</span><span class="identifier-syntax">glk_window_get_parent</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax">), </span><span class="identifier-syntax">winmethod_Fixed</span><span class="plain-syntax"> + </span><span class="identifier-syntax">winmethod_Above</span><span class="plain-syntax">, </span><span class="identifier-syntax">hgt</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">statuswin_cursize</span><span class="plain-syntax"> = </span><span class="identifier-syntax">hgt</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">VM_MoveCursorInStatusLine</span><span class="plain-syntax"> </span><span class="identifier-syntax">line</span><span class="plain-syntax"> </span><span class="identifier-syntax">column</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">glk_set_window</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">line</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="identifier-syntax">line</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="identifier-syntax">column</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">glk_window_move_cursor</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax">, </span><span class="identifier-syntax">column</span><span class="plain-syntax">-1, </span><span class="identifier-syntax">line</span><span class="plain-syntax">-1);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">statuswin_current</span><span class="plain-syntax">=1;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP17" class="paragraph-anchor"></a><b>&#167;17. Quotation Boxes. </b>On the Z-machine, quotation boxes are produced by stretching the status line,
but on Glulx they usually occupy windows of their own. If it isn't possible
to create such a window, so that <span class="extract"><span class="extract-syntax">gg_quotewin</span></span> is zero below, the quotation
text just appears in the main window.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">Box__Routine</span><span class="plain-syntax"> </span><span class="identifier-syntax">maxwid</span><span class="plain-syntax"> </span><span class="identifier-syntax">arr</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="identifier-syntax">lines</span><span class="plain-syntax"> </span><span class="identifier-syntax">lastnl</span><span class="plain-syntax"> </span><span class="identifier-syntax">parwin</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">maxwid</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="comment-syntax">squash compiler warning</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">lines</span><span class="plain-syntax"> = </span><span class="identifier-syntax">arr</span><span class="plain-syntax">--&gt;0;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">--&gt;0 = </span><span class="identifier-syntax">lines</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">glk_window_open</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_mainwin</span><span class="plain-syntax">, </span><span class="identifier-syntax">winmethod_Fixed</span><span class="plain-syntax"> + </span><span class="identifier-syntax">winmethod_Above</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">lines</span><span class="plain-syntax">, </span><span class="identifier-syntax">wintype_TextBuffer</span><span class="plain-syntax">, </span><span class="identifier-syntax">GG_QUOTEWIN_ROCK</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Quote_Window</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">parwin</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_window_get_parent</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">glk_window_set_arrangement</span><span class="plain-syntax">(</span><span class="identifier-syntax">parwin</span><span class="plain-syntax">, </span><span class="identifier-syntax">winmethod_Fixed</span><span class="plain-syntax"> + </span><span class="identifier-syntax">winmethod_Above</span><span class="plain-syntax">, </span><span class="identifier-syntax">lines</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">lastnl</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">glk_window_clear</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">glk_set_window</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">lastnl</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">VM_Style</span><span class="plain-syntax">(</span><span class="identifier-syntax">BLOCKQUOTE_VMSTY</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ix</span><span class="plain-syntax">=0 : </span><span class="identifier-syntax">ix</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">lines</span><span class="plain-syntax"> : </span><span class="identifier-syntax">ix</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">arr</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">ix</span><span class="plain-syntax">+1);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">lines</span><span class="plain-syntax">-1 || </span><span class="identifier-syntax">lastnl</span><span class="plain-syntax">) </span><span class="reserved-syntax">new_line</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">VM_Style</span><span class="plain-syntax">(</span><span class="identifier-syntax">NORMAL_VMSTY</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">glk_set_window</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_mainwin</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="S-cs.html">&#10094;</a></li><li class="progresssection"><a href="S-cpb.html">cpb</a></li><li class="progresssection"><a href="S-inf.html">inf</a></li><li class="progresssection"><a href="S-glk.html">glk</a></li><li class="progresssection"><a href="S-str.html">str</a></li><li class="progresssection"><a href="S-stt.html">stt</a></li><li class="progresssection"><a href="S-mth.html">mth</a></li><li class="progresssection"><a href="S-cs.html">cs</a></li><li class="progresscurrent">io</li><li class="progresssection"><a href="S-fio.html">fio</a></li><li class="progresssection"><a href="S-vnr.html">vnr</a></li><li class="progresssection"><a href="S-vn.html">vn</a></li><li class="progressnext"><a href="S-fio.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

